<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户登录</title>
    <style>
        /* 全局样式 */
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Segoe UI', 'PingFang SC', 'Microsoft Yahei', sans-serif;
            background: linear-gradient(135deg, #e0f7fa, #f3e5f5);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 40px 20px;
            color: #333;
        }

        .card {
            background: white;
            width: 100%;
            max-width: 400px;
            padding: 30px 25px;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            transition: all 0.3s ease;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
        }

        h2 {
            text-align: center;
            margin-bottom: 24px;
            font-weight: 600;
            color: #374151;
        }

        label {
            display: block;
            margin-bottom: 5px;
            color: #4b5563;
        }

        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 8px;
            margin-bottom: 1rem;
            border: 1px solid #ccc;
            border-radius: 6px;
        }

        button {
            width: 100%;
            padding: 10px;
            background-color: #d1ecf1;
            color: #15576b;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
        }

        button:hover {
            background-color: #aee2eb;
            color: #0f3d4d;
        }

        .error {
            color: red;
            text-align: center;
            margin-bottom: 1rem;
        }

        .btn-link {
            display: inline-block;
            margin-top: 1rem;
            text-align: center;
            color: #15576b;
            text-decoration: none;
        }

        .btn-link:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>

<div class="card">
    <h2>用户登录</h2>
    <% if (request.getAttribute("error") != null) { %>
    <p class="error"><%= request.getAttribute("error") %></p>
    <% } %>
    <form action="LoginServlet" method="post" onsubmit="return validateForm()">
        <label for="username">用户名:</label>
        <input type="text" id="username" name="username" required>

        <label for="password">密码:</label>
        <input type="password" id="password" name="password" required>

        <button type="submit">立即登录</button>
    </form>
    <br/>
    <a href="register.jsp" class="btn-link">没有账号？立即注册</a>
</div>

<script>
    function validateForm() {
        const username = document.getElementById('username').value.trim();
        const password = document.getElementById('password').value.trim();
        if (username.length < 3) {
            alert('用户名至少需要3个字符');
            return false;
        }
        if (password.length < 6) {
            alert('密码长度不能少于6位');
            return false;
        }
        return true;
    }
</script>

</body>
</html>
